<?php
function cpanel_info($context) {
	if ($context) {
		switch ($context) {
			case "modinfo":
				$M = array();
					$config = array();
					$config['title'] = "cPanel";
					$config['modref'] = "cpanel";
					$config['icon'] = null;//optional
						$includes = array();
							$head = array();
								$head['js']['local'] = array();
								//$head['js']['local'][] = "<script>alert('Script Head Include');</script>\n";
								$head['js']['external'] = array();
								//$head['js']['external'][] = "<script src='file.js'></script>\n";

								$head['css']['local'] = array();
									//$head['css']['local'][] = "<style type='text/css'>.body {font-size:10px;}</style>\n";
								$head['css']['external'] = array();
									//$head['css']['external'][] = "<link type=\"text/css\" rel=\"stylesheet\" media=\"all\" href=\"mycssfile.css\" />\n";
						$includes['head'] = $head;
							$page['body'] = array();
								$page['body']['js']['local'] = array();
								
								$page['body']['js']['external'] = array();
						$incluldes['body'] = $page['body'];
					$config['includes'] = $includes;
					//$config[''] = null;
				$M['config'] = $config;
				return $M;
			break;
			case "help":
				$page = array();
				$page['title'] = "cPanel Help";
				$page['body'] = "<p>help content here</p>\n";
			break;
			case "about":
				$page = array();
				$page['title'] = "About cPanel";
				$page['body'] = "<p>Safe-Harbour cPanel Page module designed by mike@ox-code.org</p>\n";
			break;
		}//switch context
	}
}
function cpanel_theme_cpanel_icons($Q,$default,$input) {
$html = "";
	$html .= "<div class='cpanel-icon-outer'><a href='".$input['link']."'><img src='".$input['icon']."' /></a><br /><a href='".$input['link']."'>".$input['label']."</a></div>\n";
return $html;
}
function cpanel_task(&$Q,$dblayer,$providers,$params) {
$page = array();
$page['title'] = "";
$page['body'] = "";
	if (isset($params['task'])) {
		$task = $params['task'];
		$modref = "";
		if (isset($params['modref'])) {
			$modref = $params['modref'];
		}
		switch ($task) {
		default:
			$Q['head']['css'][] = $Q{'base_url'}."/system/modules/{$modref}/style.css";
			$page['title'] .= "Safe-Harbour@Enlightenment";
			$current_user = current_user($dblayer);
			$permitted_modules = array_to_query_list(permitted_modules($dblayer,$current_user['id']));
			$modules = $dblayer->query("SYSTEM",sprintf("select * from modules where mid IN %s",$permitted_modules));
				if ($modules->num_rows) {
					while ($m = $modules->fetch_object()) {
						if ($m->modref != system_get_var($dblayer,"system_default_module")) {
							//check if a modref_cpanel() function exists
							if (router_load_module($Q,$dblayer,$m->modref)) {
								if (function_exists($m->modref."_cpanel")) {
									$iconParams = array();
									$iconParams['modref'] = $m->modref;
									$evalcode = "\$icons = ".$m->modref."_cpanel(\$Q,\$dblayer,\$iconParams);";
									eval($evalcode);
									if (isset($icons)) {
										if (count($icons)) {
											//$customIcon = true;
											$themeparams = array();
											$themeparams['modref'] = $modref;
											$themeparams['profile'] = "cpanel_icons";
											foreach ($icons as $icon) {
												$page['body'] .= theme($Q,$dblayer,$icon,$themeparams);
											}
										}//if count icons
									}//if isset icons
								}
							}
						}
					}// while ($m->row = mysql_fetch_assoc($m->query)) ;
				} else {
					$page['body'] .= "<p class='error'>You do not have access to any modules.</p>";
				}
		break;
		}//switch task
	}
return $page;
}

/**
Calling the module:

$function_call = "\$myvar = {$modref}_info('modinfo');";
eval($function_call);
if (isset($myvar)) {
	//the call worked and we have our result.
}
**/
?>
